package com.example.java.Service;

import sun.misc.BASE64Decoder;

import java.io.FileOutputStream;

public class Base {

    public String face(String userImgSrc) {
        String[] str = userImgSrc.split(",");
        userImgSrc = str[1];
        String imgInfo = str[0];
        String imgExt = imgInfo.split("/")[1].split(";")[0];
        BASE64Decoder decoder = new BASE64Decoder();
        byte[] b = null;
        FileOutputStream out = null;
        try {


            b  = decoder.decodeBuffer(userImgSrc);
            for (int i = 0; i < b.length; i++){
                if (b[i]<0){
                    b[i]+=256;
                }
            }
            String imgFilePath = "C:\\Users\\zl133\\Desktop";
            out = new FileOutputStream(imgFilePath);


        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try {
                out.write(b);
                out.flush();
                out.close();
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        return null;
    }

}
